package 蓝桥杯算法;

public class day33 {
    public static void main(String[] args) {

        int result=0;
        int count=0;
        int[][]arr={{0,0,0,0,0},{0,1,0,1,0},{0,1,1,1,0},{0,1,1,1,0},{0,0,0,0,0}};
        for(int i=0;i<5;i++){
            for(int j=0;j<5;j++){
                if(arr[i][j]==1){
                    //遍历到一个新的
                    count=0;
                    helper(arr,i,j,count);
                    result+=count;
                }
            }
        }
        System.out.println(result);
    }
    public static void  helper(int[][] graph, int x, int y, int count){
        int[][] dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
        int nx=0;
        int ny=0;
       for(int[] d:dirs) {
           nx = x + d[0];
           ny = y + d[1];
           if (nx < 0 || nx >= graph.length || ny < 0 || ny >= graph[0].length || graph[nx][ny] == 0) {
               count++;
           }
       }
    }
}
